import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [

  {
    path: '/SMSLogin',
    component: () => import('@/views/SMSLogin/index'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/agreement',
    component: () => import('@/views/agreement/index'),
    hidden: true
  },
  {
    path: '/verify/agreement',
    component: () => import('@/views/verify/agreement'),
    hidden: true
  },
  {
    path: '/reset',
    component: () => import('@/views/reset/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/summary',
    children: [{
      path: 'summary',
      name: 'Dashboard',
      component: () => import('@/views/summary/index'),
      meta: { title: '概况', icon: 'summary' }
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/word',
    children: [ {
      path: 'word',
      // name: 'finance',
      component: () => import('@/views/word/index'),
      meta: {title: '违禁词管理', icon: 'form'}
    },
      {
        path: 'word/add',
        // name: 'finance',
        component: () => import('@/views/word/add-word'),
        meta: {title: '新增违禁词', icon: 'form'}
      },]
  },

  {
    path: '/verify',
    component: Layout,
    redirect: '/verify/index',
    name: 'Example',
    meta: { title: '企业基本信息', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: 'verify',
        component: () => import('@/views/verify/index'),
        meta: { title: '企业认证', icon: 'table' }
      },
      {
        path: 'site',
        name: 'site',
        component: () => import('@/views/site/index'),
        meta: { title: '站点管理', icon: 'table' }
      },
      {
        path: 'add-site',
        name: 'add-site',
        component: () => import('@/views/site/addSite'),
        meta: { title: '添加站点', icon: 'table' }
      },
      {
        path: 'companys',
        name: 'companys',
        component: () => import('@/views/verify/companyList'),
        meta: { title: '企业列表', icon: 'table' }
      },
      {
        path: 'detail',
        name: 'detail',
        component: () => import('@/views/verify/verify-detail'),
        meta: { title: '企业详情', icon: 'table' }
      },

      // {
      //   path: 'agreement',
      //   name: 'Agreement',
      //   component: () => import('@/views/verify/agreement'),
      //   meta: {title: '认证协议', icon: 'table'}
      // },
    ]
  },
  {
    path: '/promote',
    component: Layout,
    meta: { title: '推广管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '',
        name: 'Promote',
        component: () => import('@/views/promote/index'),
      }
    ]
  },
  {
    path: '/finance',
    component: Layout,
    meta: { title: '财务管理', icon: 'form' },
    children: [
      {
        path: '',
        redirect: "info",
        name: 'finance',
        component: () => import('@/views/finance/index'),
        children: [
          {
            path: 'info',
            // name: 'finance',
            component: () => import('@/views/finance/info/index'),
            meta: { title: '财务信息', icon: 'form' }
          },
          {
            path: 'global',
            // name: 'finance',
            component: () => import('@/views/finance/global/index'),
            meta: { title: '财务信息汇总', icon: 'form' }
          },
          {
            path: 'discount',
            // name: 'finance',
            component: () => import('@/views/finance/discount/index'),
            meta: { title: '优惠记录', icon: 'form' }
          },
          {
            path: 'coupon',
            // name: 'finance',
            component: () => import('@/views/finance/coupon/index'),
            meta: { title: '优惠券管理', icon: 'form' }
          },
          {
            path: 'invoice',
            // name: 'finance',
            component: () => import('@/views/finance/invoice/index'),
            meta: { title: '发票管理', icon: 'form' },
          },
          {
            path: 'invoice/add',
            // name: 'finance',
            component: () => import('@/views/finance/invoice/add-invoice'),
            meta: { title: '新建发票', icon: 'form' }
          }, {
            path: 'invoice/details',
            // name: 'finance',
            component: () => import('@/views/finance/invoice/invoice-detail'),
            meta: { title: '查看发票', icon: 'form' }
          }, {
            path: 'recharge',
            // name: 'finance',
            component: () => import('@/views/finance/recharge/index'),
            meta: { title: '在线充值', icon: 'form' }
          },
          {
            path: 'refund',
            // name: 'auditing',
            component: () => import('@/views/finance/refund/index'),
            meta: { title: '退款记录', icon: 'form' }
          },
          {
            path: 'refund/auditing',
            component: () => import('@/views/finance/refund/auditingRefund'),
            meta: { title: '退款详情', icon: 'form' }
          },
          {
            path: 'refund/add',
            // name: 'finance',
            component: () => import('@/views/finance/refund/add-refund'),
            meta: { title: '退款申请', icon: 'form' }
          }
        ]
      }
    ]
  },
  {
    path: '/notice',
    component: Layout,
    name: 'sys-notice',
    meta: {
      title: '系统通知',
      icon: 'nested'
    },
    children: [
      {
        path: '',
        redirect: "sys",
        name: 'notification',
        component: () => import('@/views/notification/index'),
        children: [
          {
            path: 'sys',
            component: () => import('@/views/notification/sys/index'),
            meta: { title: '系统公告', icon: 'form' }
          },
          {
            path: 'sys/add',
            component: () => import('@/views/notification/sys/addSys'),
            meta: { title: '增加系统公告', icon: 'form' }
          },
          {
            path: 'news',
            component: () => import('@/views/notification/news/index'),
            meta: { title: '消息提醒', icon: 'form' }
          },
          {
            path: 'feedback',
            component: () => import('@/views/notification/feedback/index'),
            meta: { title: '问题反馈', icon: 'form' }
          },
          {
            path: 'feedback/add',
            component: () => import('@/views/notification/feedback/add'),
            meta: { title: '新增反馈', icon: 'form' }
          },
          {
            path: 'feedback/info',
            component: () => import('@/views/notification/feedback/add'),
            meta: { title: '问题反馈', icon: 'form' }
          },
          {
            path: 'help',
            component: () => import('@/views/notification/help/index'),
            meta: { title: '帮助信息', icon: 'form' }
          },
          {
            path: 'help/add',
            component: () => import('@/views/notification/help/add'),
            meta: { title: '添加帮助', icon: 'form' }
          },
        ]
      }
    ]
  },
  {
    path: "/account",
    component: Layout,
    name: 'account',
    meta: {
      title: '账号管理',
      icon: 'nested'
    },
    children: [
      {
        path: '',
        redirect: "ent",
        name: 'account-info',
        component: () => import('@/views/account/index'),
        children: [

          {
            path: 'ent',
            name: 'account-info',
            component: () => import('@/views/account/enterprise/index'),
            meta: {
              title: '企业账号管理',
            }
          },

          {
            path: 'Logout-list',
            name: 'Logout-list',
            component: () => import('@/views/account/Logout-list/index'),
            meta: {
              title: 'Logout-list',
            }
          },
          {
            path: 'ent/add',
            name: 'account-info',
            component: () => import('@/views/account/enterprise/add-new'),
            meta: {
              title: '新建账号',
            }
          },
          {
            path: 'ent/editUser',
            name: 'account-info',
            component: () => import('@/views/account/enterprise/edit-user'),
            meta: {
              title: '编辑普通操作员账号',
            }
          },
          {
            path: 'ent/editEnt',
            name: 'account-info',
            component: () => import('@/views/account/enterprise/edit-ent'),
            meta: {
              title: '编辑企业账号',
            }
          },
          {
            path: 'ent/pwd',
            name: 'account-info',
            component: () => import('@/views/account/enterprise/edit-pwd'),
            meta: {
              title: '修改密码',
            }
          },
          {
            path: 'user',
            redirect: "user/info",
            name: 'account-info',
            component: () => import('@/views/account/user/index'),
            children: [
              {
                path: 'info',
                name: 'account-info',
                component: () => import('@/views/account/user/info/index'),
                meta: { title: '账号管理', icon: 'form' }

              },
              {
                path: 'pwd',
                name: 'account-info',
                component: () => import('@/views/account/user/password/index'),
                meta: { title: '修改密码', icon: 'form' }

              },
              {
                path: 'cancel',
                name: 'account-info',
                component: () => import('@/views/account/user/logout/index'),
                meta: { title: '注销账号', icon: 'form' }
              },

            ]
          },

        ]
      }

    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
